import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { ColorConfig } from "../../resource/ColorConfig";
import { ItemData } from "../../resource/info/ItemData";
import { ECategory } from "../../../../Message/Public/ECategory";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { EffectManager } from "../../manager/EffectManager";
import { EProp } from "../../../../Message/Public/EProp";
import { ObjCreate } from "../common/ObjCreate";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { BaseItem } from "../common/BaseItem";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../com/mui/controls/GButton";
import { BuyAlert } from "../pet/BuyAlert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PreviewType } from "./PreviewType";
import { TItem } from "../../../../Message/Db/Tables/TItem";
import { ColorInfo } from "../../resource/info/ColorInfo";
import { LineBox } from "../guide/LineBox";
import { PreviewAvatar } from "../../../../PreviewType/PreviewAvatar";
import { PreviewPet } from "../../../../PreviewType/PreviewPet";
import { PreviewMount } from "../../../../PreviewType/PreviewMount";
type int = number;
//class PropsRender
    
    export  class PropsRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._pIngot = new Object /* flash.display.Bitmap */();
            this.createChildren();
            return;
        }

        /* internal  */updateBitmap(): void
        {
            if (this.label != 0) 
            {
                if (this.label != 1) 
                {
                    if (this.label == 2) 
                    {
                        this._labelBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.HotLabel);
                    }
                }
                else 
                {
                    this._labelBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.NewLabel);
                }
            }
            else 
            {
                this._labelBitmap.bitmapData = null;
            }
            return;
        }

        protected /* override */ draw(): void
        {
            super.draw();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            return;
        }

        
        {
            PropsRender.isWider = false;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            if (_data == arg1) 
            {
                return;
            }
            super.data = arg1;
            this.shopItemInfo = arg1["shopItemInfo"] as ShopItemInfo;
            this.isHighlight = arg1["isHighlight"] as Boolean;
            this._numericStepper.value = this.shopItemInfo.buyNum;
            if (this.shopItemInfo && this.shopItemInfo.itemInfo) 
            {
                this.label = this.shopItemInfo.tshopSell.label;
                this._priceType = this.shopItemInfo.unit;
                this.itemInfo = this.shopItemInfo.itemInfo.item;
                this._activeOffer = this.shopItemInfo.tshopSell.activeOffer;
                this._price = this.shopItemInfo.tshopSell.price;
                this._offer = this.shopItemInfo.tshopSell.offer;
                this.colorInfo = ColorConfig.instance.getItemColor(this.itemInfo.color);
                if (this.colorInfo) 
                {
                    this.colorName = this.colorInfo.color;
                }
                loc1 = new ItemData(this.itemInfo.code);
                this.category = loc1.category;
                this.type = loc1.type;
                if (loc1.category != ECategory._ECategoryMount) 
                {
                    this._propItem.toolTipType = ItemData.ToolTipType_Pack;
                }
                else 
                {
                    this._propItem.toolTipType = ItemData.ToolTipType_Mounts;
                }
                this._propItem.itemData = loc1;
                this._propItem.drawNow();
                this._propItem.amount = -1;
                this._propItem.setSize(60, 60);
                this._nameLabel.htmlText = HTMLUtil.addColor(this.itemInfo.name, this.colorName);
                this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
                if (this._priceImgName != "") 
                {
                    this._oIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                    this._pIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                }
                if (Cache.instance.shop.isShopMallDiscount && this._activeOffer > 0 || this._offer > 0) 
                {
                    if (!this.contains(this._oPriceLabel)) 
                    {
                        this._oPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
                        this._oPriceLabel.x = 80;
                        this._oPriceLabel.y = 18;
                        this.addChild(this._oPriceLabel);
                    }
                    if (!this.contains(this._oPriceNumLabel)) 
                    {
                        this.addChild(this._oPriceNumLabel);
                    }
                    if (!this.contains(this._oIngot)) 
                    {
                        this.addChild(this._oIngot);
                    }
                    if (!this.contains(this._redLine)) 
                    {
                        this.addChild(this._redLine);
                    }
                    this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
                    this._pPriceLabel.x = 80;
                    this._pPriceLabel.y = 35;
                    this._oPriceNumLabel.htmlText = HTMLUtil.addColor(this.shopItemInfo.tshopSell.price.toString(), "#B0EFFF");
                    if (this._activeOffer > 0) 
                    {
                        this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this._activeOffer.toString(), "#F4FF01");
                    }
                    else if (this._offer > 0) 
                    {
                        this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this._offer.toString(), "#F4FF01");
                    }
                    else 
                    {
                        this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this._price.toString(), "#F4FF01");
                    }
                    this._pPriceNumLabel.x = 135;
                    this._pPriceNumLabel.y = 35;
                    this._pIngot.x = 170;
                    this._pIngot.y = 40;
                    loc2 = this._oPriceNumLabel.y;
                    loc3 = this._oPriceNumLabel.x + this._oPriceNumLabel.width;
                    loc4 = this._oPriceNumLabel.x + (40 - this._oPriceNumLabel.textField.width);
                    this._redLine.graphics.clear();
                    this._redLine.graphics.lineStyle(2, 16711680, 0.75);
                    this._redLine.graphics.moveTo(loc4, loc2);
                    this._redLine.graphics.lineTo(loc3, this._oPriceNumLabel.y + this._oPriceNumLabel.textField.height);
                }
                else 
                {
                    if (this.contains(this._oPriceLabel)) 
                    {
                        this.removeChild(this._oPriceLabel);
                    }
                    if (this.contains(this._oPriceNumLabel)) 
                    {
                        this.removeChild(this._oPriceNumLabel);
                    }
                    if (this.contains(this._oIngot)) 
                    {
                        this.removeChild(this._oIngot);
                    }
                    if (this.contains(this._redLine)) 
                    {
                        this.removeChild(this._redLine);
                    }
                    this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53020), "#00FF1F");
                    this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this.shopItemInfo.tshopSell.price.toString(), "#F4FF01");
                    this._pPriceLabel.move(80, 25);
                    this._pPriceNumLabel.move(135, 25);
                    this._pIngot.x = 170;
                    this._pIngot.y = 27;
                }
            }
            LoaderHelp.addResCallBack(ResFileConst.shopMall, this.updateBitmap);
            if (this.isHighlight) 
            {
                if (this._lineBox == null) 
                {
                    this._lineBox = EffectManager.getLineBox(width - 2, height - 22, [16711680, 16776960]);
                    this._lineBox.x = 2;
                    this._lineBox.y = 2;
                }
                if (!this.contains(this._lineBox)) 
                {
                    this.addChild(this._lineBox);
                }
            }
            else if (this._lineBox != null) 
            {
                if (this.contains(this._lineBox)) 
                {
                    this.removeChild(this._lineBox);
                }
            }
            if (this.category == ECategory._ECategoryMount || this.category == ECategory._ECategoryProp && this.type == EProp._EPropPetEgg || this.category == ECategory._ECategoryProp && this.type == EProp._EPropChangeAvatar) 
            {
                if (this._previewBtn == null) 
                {
                    this._previewBtn = ObjCreate.createGButton(Language.getString(53012), 155, 2, 40, 20, this);
                    this._previewBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPreviewBtnClickHandler);
                }
                this._previewBtn.drawNow();
                this.addChild(this._previewBtn);
            }
            else if (this._previewBtn && this.contains(this._previewBtn)) 
            {
                this.removeChild(this._previewBtn);
            }
            if (PropsRender.isWider) 
            {
                this._windowCenterB.width = 210;
            }
            else 
            {
                this._windowCenterB.width = 200;
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._windowCenterB = ResouceConst.getScaleBitmap("WindowCenterB");
            this._windowCenterB.width = 200;
            this._windowCenterB.height = 82;
            this.addChild(this._windowCenterB);
            this._bg = GlobalClass.getBitmap("PropBg");
            this._bg.x = 5;
            this._bg.y = 7;
            this.addChild(this._bg);
            this._propItem = new BaseItem();
            this._propItem.isDragAble = false;
            this._propItem.label = "";
            this._propItem.move(10, 12);
            this.addChild(this._propItem);
            this._labelBitmap = new Object /* flash.display.Bitmap */();
            this._labelBitmap.x = 5;
            this._labelBitmap.y = 7;
            this.addChild(this._labelBitmap);
            ObjCreate.createBg(80, 0, 110, 20, this, ImagesConst.SelectedBg);
            this._nameLabel = new GLabel();
            this._nameLabel.x = 80;
            this._nameLabel.y = 2;
            this.addChild(this._nameLabel);
            this._oPriceLabel = new GLabel();
            this._oPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._oPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
            this._oPriceLabel.x = 80;
            this._oPriceLabel.y = 18;
            this.addChild(this._oPriceLabel);
            this._oPriceNumLabel = new GLabel();
            this._oPriceNumLabel.width = 40;
            this._oPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._oPriceNumLabel.x = 130;
            this._oPriceNumLabel.y = 18;
            this.addChild(this._oPriceNumLabel);
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._oIngot.x = 170;
            this._oIngot.y = 20;
            this.addChild(this._oIngot);
            this._pIngot = new Object /* flash.display.Bitmap */();
            this._pIngot.x = 170;
            this._pIngot.y = 40;
            this.addChild(this._pIngot);
            this._redLine = new Object /* flash.display.Shape */();
            this.addChild(this._redLine);
            this._pPriceLabel = new GLabel();
            this._pPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
            this._pPriceLabel.x = 80;
            this._pPriceLabel.y = 35;
            this.addChild(this._pPriceLabel);
            this._pPriceNumLabel = new GLabel();
            this._pPriceNumLabel.width = 35;
            this._pPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._pPriceNumLabel.x = 150;
            this._pPriceNumLabel.y = 35;
            this.addChild(this._pPriceNumLabel);
            this._numericStepper = new GNumericStepper();
            this._numericStepper.setSize(60, 22);
            this._numericStepper.move(80, 55);
            this._numericStepper.styleName = "NumericStepper";
            this._numericStepper.addEventListener(flash.events.Event.CHANGE, this.onBuyNumChange);
            this._numericStepper.drawNow();
            this._numericStepper.textField.setStyle("upSkin", GlobalClass.getScaleBitmap("WindowCenterB", new Object /* flash.geom.Rectangle */(4, 4, 36, 21)));
            this._numericStepper.textField.drawNow();
            this._numericStepper.maximum = 99;
            this._numericStepper.minimum = 1;
            this.addChild(this._numericStepper);
            this._buyBtn = new GButton();
            this._buyBtn.label = Language.getString(53021);
            this._buyBtn.styleName = "Button";
            this._buyBtn.setSize(50, 24);
            this._buyBtn.move(145, 55);
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickhandler);
            this.addChild(this._buyBtn);
            return;
        }

        /* internal  */onBuyNumChange(arg1: Object /* flash.events.Event */): void
        {
            this.shopItemInfo.buyNum = this._numericStepper.value;
            return;
        }

        protected onBuyBtnClickhandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._numericStepper.value;
            if (this.shopItemInfo) 
            {
                this.shopItemInfo.buyNum = loc1;
                BuyAlert.showByShopItemInfo(this.shopItemInfo);
            }
            return;
        }

        /* internal  */onPreviewBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            if (this.category != ECategory._ECategoryMount) 
            {
                if (this.category == ECategory._ECategoryProp && this.type == EProp._EPropChangeAvatar) 
                {
                    loc1 = this.itemInfo.code;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetMountPreview, {"type": PreviewAvatar, "code": loc1}));
                }
                else 
                {
                    loc1 = this.itemInfo.effect;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetMountPreview, {"type": PreviewPet, "code": loc1}));
                }
            }
            else 
            {
                loc1 = this.itemInfo.code;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMountPreview, {"type": PreviewMount, "code": loc1}));
            }
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_oPriceLabel: GLabel;

        /* internal */ /* var */_pPriceLabel: GLabel;

        /* internal */ /* var */_oPriceNumLabel: GLabel;

        /* internal */ /* var */_pPriceNumLabel: GLabel;

        /* internal */ /* var */_oIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_pIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_windowCenterB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_labelBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_numericStepper: GNumericStepper;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string;

        protected /* var */shopItemInfo: ShopItemInfo;

        /* internal */ /* var */itemInfo: TItem;

        /* internal */ /* var */_redLine: Object /* flash.display.Shape */;

        /* internal */ /* var */_activeOffer: int;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_offer: int;

        /* internal */ /* var */_previewBtn: GButton;

        public /* var */isHighlight: Boolean=false;

        /* internal */ /* var */colorInfo: ColorInfo;

        /* internal */ /* var */colorName: string;

        /* internal */ /* var */label: int;

        /* internal */ /* var */category: int;

        /* internal */ /* var */type: int;

        public static /* var */isWider: Boolean=false;

        /* internal */ /* var */_lineBox: LineBox;
    }
